package com.sinacom.ibuilding.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.sinacom.ibuilding.beans.Member;
import com.sinacom.ibuilding.beans.Role;
import com.sinacom.ibuilding.service.MemberService;
import com.sinacom.ibuilding.service.MessageService;
import com.sinacom.ibuilding.service.NewsService;
import com.sinacom.ibuilding.util.Helper;

public class IndexAction {
	
	private MessageService messgeService = new MessageService();
	private MemberService memberService = new MemberService();
	private NewsService newsService = new NewsService();

	private List mailList;
	private List highList;//高招
	private List middelList;//中招
	private List startList;//初中
	private List primaryList;//小学
	private List childList;//幼儿园
	private List examList;//学业考试
	private List rollmList;//中学学籍
	private List rollsList;//小学学籍
	private List infoList;//教学信息
	
	private List announceList;//公告
	private List shortList;//短消息
	private int noReadCount;//未读邮件数
	public String index()throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		Member member = (Member) request.getSession().getAttribute("member");
	    
		Role role = member.getRole();
		String accessRes = role.getAccessRes();
		if(!StringUtils.isEmpty(accessRes)){ 
			String[] ress = accessRes.split(",");
			
			for (int i = 0; i < ress.length; i++) { 
				List list = newsService.getIndexNewsCategory(ress[i], null);
				Helper.newList(list);
				
				switch(Integer.parseInt(ress[i])){
					case 1:{
						highList = list;
						break;
					}
					case 2:{
						middelList = list;
						break;
					}
					case 3:{
						startList = list;
						break;
					}
					case 4:{
						primaryList = list;
						break;
					}
					case 5:{
						childList = list;
						break;
					}
					case 6:{
						examList = list;
						break;
					}
					case 7:{
						rollmList = list;
						break;
					}
					case 8:{
						rollsList = list;
						break;
					}
					case 9:{
						infoList = list;
						break;
					}
					default:
						break;
					
				}
			}
		}
		announceList = newsService.getIndexAnnounce(); 
		Helper.newList(announceList);
	    mailList = messgeService.getIndexEmail(member); 
	    shortList = messgeService.getIndexShort(member);
	    noReadCount = messgeService.getNoReadEmail(member);
		return "index";
	}
	
	
	
    public MessageService getMessgeService() {
        return messgeService;
    }
    public void setMessgeService(MessageService messgeService) {
        this.messgeService = messgeService;
    }
	public List getMailList() {
		return mailList;
	}
	public void setMailList(List mailList) {
		this.mailList = mailList;
	}
	public MemberService getMemberService() {
		return memberService;
	}
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	public NewsService getNewsService() {
		return newsService;
	}
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}
	public List getHighList() {
		return highList;
	}
	public void setHighList(List highList) {
		this.highList = highList;
	}
	public List getMiddelList() {
		return middelList;
	}
	public void setMiddelList(List middelList) {
		this.middelList = middelList;
	}
	public List getStartList() {
		return startList;
	}
	public void setStartList(List startList) {
		this.startList = startList;
	}
	public List getPrimaryList() {
		return primaryList;
	}
	public void setPrimaryList(List primaryList) {
		this.primaryList = primaryList;
	}
	public List getChildList() {
		return childList;
	}
	public void setChildList(List childList) {
		this.childList = childList;
	}
	public List getExamList() {
		return examList;
	}
	public void setExamList(List examList) {
		this.examList = examList;
	}
	public List getRollmList() {
		return rollmList;
	}
	public void setRollmList(List rollmList) {
		this.rollmList = rollmList;
	}
	public List getRollsList() {
		return rollsList;
	}
	public void setRollsList(List rollsList) {
		this.rollsList = rollsList;
	}
	public List getInfoList() {
		return infoList;
	}
	public void setInfoList(List infoList) {
		this.infoList = infoList;
	}
	public List getAnnounceList() {
		return announceList;
	}
	public void setAnnounceList(List announceList) {
		this.announceList = announceList;
	}
	public List getShortList() {
		return shortList;
	}
	public void setShortList(List shortList) {
		this.shortList = shortList;
	}
	public int getNoReadCount() {
		return noReadCount;
	}
	public void setNoReadCount(int noReadCount) {
		this.noReadCount = noReadCount;
	}
	
	
	
	
}
